// 统一管理接口
import request from "../../utils/request";
import type { AdminRole, GetAdminRoleMenuResponseData, GetAdminRoleResponseData, GetMenuResponseData, GetPageData, GetUserListResponseData, GetUserRoleInfoResponse, loginFormData, loginResponseData, passwordData, UpdateUserRoleData, UserInfo, UserInfoResponseData } from './type'
enum API {
    // 用户登录接口 POST
    LOGIN_URL = '/user/login',
    // 获取用户信息 GET
    USERINFO_URL = '/user/userInfo',
    // 退出登录接口 POST
    LOGINOUT_URL = '/user/logout',
    // 获取用户列表信息 POST
    GETUSERLIST_URL = '/user/userList',
    // 修改用户角色 禁用账号 PUT
    UPDATEUSEROLE_URL = '/user/userEdit',
    // 获取用户角色信息 GET
    GETUSERROLEINFO_URL = '/role/getUserRoleList',
    // 获取管理员列表 POST
    GETADMINLIST_URL = '/user/adminList',
    // 修改管理员角色 PUT
    UPDATEADMININFO_URL = '/user/adminEdit',
    // 删除管理员 DELETE userId
    DELETEADMIN_URL = '/user/adminDel',
    // 新增管理员 POST
    ADDADMIN_URL = '/user/adminAdd',
    // 新增管理员角色 POST
    ADDADMINROLE_URL = '/role/roleAdd',
    // 获取管理员角色列表 GET
    GETADMINROLELIST_URL = '/role/getRoleList',
    // 编辑角色 POST
    EDITROLE_URL = '/role/roleEdit',
    // 获取角色菜单 GET roleId
    GETROLEMENU_URL = '/role/roleMenu',
    // 保存角色菜单 POST roleId
    SAVEROLEMENU_URL = '/role/roleMenu',
    // 获取菜单 GET
    GETMENU_URL = '/menu/menuList',
    // 删除角色 DELETE
    DELETEROLE_URL = '/role/roleDel',
    // 修改当前账号信息 POST
    UPDATEMYINFO_URL = 'user/updateMyInfo',
    // 修改密码
    UPDATEPASSWORD_URL = '/user/updatePassword'
}

// 对外暴露请求函数
export const reqLogin = (data: loginFormData) => request.post<any, loginResponseData>(API.LOGIN_URL, data)
// 获取用户信息
export const reqUserInfo = () => request.get<any, UserInfoResponseData>(API.USERINFO_URL)
// 退出登录
export const reqLoginOut = () => request.post<any, any>(API.LOGINOUT_URL)
// 获取用户列表
export const reqGetUserList = (data: GetPageData) => request.post<any, GetUserListResponseData>(API.GETUSERLIST_URL, data)
// 修改用户角色 禁用、启用账号
export const reqUpdateUserRole = (data: UpdateUserRoleData) => request.put<any, any>(API.UPDATEUSEROLE_URL, data)
// 获取用户角色信息 贫困户 普通用户
export const reqUserRoleInfo = () => request.get<any, GetUserRoleInfoResponse>(API.GETUSERROLEINFO_URL)
// 获取管理员列表
export const reqGetAdminList = (data: GetPageData) => request.post<any, GetUserListResponseData>(API.GETADMINLIST_URL, data)
// 修改管理员角色
export const reqUpdateAdminRole = (data: UserInfo) => request.put<any, any>(API.UPDATEADMININFO_URL, data)
// 删除管理员
export const reqDeleteAdmin = (userId: number | string) => request.delete<any, any>(API.DELETEADMIN_URL + `?userId=${userId}`)
// 新增管理员账号
export const reqAddAdmin = (data: UserInfo) => request.post<any, any>(API.ADDADMIN_URL, data)
// 新增管理员角色
export const reqAddAdminRole = (data: any) => request.post<any, any>(API.ADDADMINROLE_URL, data)
// 获取管理员角色列表
export const reqGetAdminRoleList = () => request.get<any, GetAdminRoleResponseData>(API.GETADMINROLELIST_URL)
// 编辑管理员角色信息
export const reqEditAdminRoleInfo = (data: AdminRole) => request.post<any, any>(API.EDITROLE_URL, data)
// 新增管理员角色
export const reqAddAdminRoleInfo = (data: AdminRole) => request.post<any, any>(API.ADDADMINROLE_URL, data)
// 获取角色菜单
export const reqGetRoleMenu = (roleId: number) => request.get<any, GetAdminRoleMenuResponseData>(API.GETROLEMENU_URL + `/${roleId}`)
// 获取菜单
export const reqGetMenu = () => request.get<any, GetMenuResponseData>(API.GETMENU_URL)
// 删除角色
export const reqDeleteRole = (roleId: number) => request.delete<any, any>(API.DELETEROLE_URL + `?roleId=${roleId}`)
// 给相应的角色分配菜单
export const reqSaveMenu = (data: number[], roleId: number) => request.post<any, any>(API.SAVEROLEMENU_URL + `/${roleId}`, data)
// 修改当前账号的信息
export const reqUpdateMyInfo = (data: UserInfo) => request.post<any, any>(API.UPDATEMYINFO_URL, data)
// 修改密码
export const reqUpdatePassword = (data: passwordData) => request.post<any, any>(API.UPDATEPASSWORD_URL, data)
